//
//  SXTMyPageHeadView.m
//  SYT
//
//  Created by 彭之耀 on 2017/8/27.
//  Copyright © 2017年 个人学习. All rights reserved.
//

#import "SXTMyPageHeadView.h"

@interface SXTMyPageHeadView ()

@property(strong,nonatomic) UIImageView *headBackImg;   //顶部背景图片
@property(strong,nonatomic) UIButton *loginButton;      //注册按钮
@property(strong,nonatomic) UIButton *registerButton;   //登录按钮

@end

@implementation SXTMyPageHeadView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

-(instancetype)init{
    self = [super init];
    if (self) {
        [self addSubview:self.headBackImg];
        [self addSubview:self.loginButton];
        [self addSubview:self.registerButton];
    }
    return self;
}

-(void)layoutSubviews{
    __weak typeof (self) weakSelf = self;
    [_headBackImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(weakSelf);
        
    }];
    [_loginButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(weakSelf.mas_centerX).offset(-60);
        make.centerY.equalTo(weakSelf.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(45, 23));
    }];
    [_registerButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(weakSelf.mas_centerX).offset(60);
        make.centerY.equalTo(weakSelf.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(45, 23));
    }];
}

-(UIImageView *)headBackImg{
    if (! _headBackImg) {
        _headBackImg = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"我的背景"]];
    }
    return _headBackImg;
}

-(UIButton *)loginButton{
    if (!_loginButton) {
        _loginButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_loginButton setTitle:@"登录" forState:UIControlStateNormal];
        _loginButton.titleLabel.font = [UIFont systemFontOfSize:18.0f];
        _loginButton.titleLabel.textColor = [UIColor whiteColor];
    }
    return _loginButton;
}

-(UIButton *)registerButton{
    if (!_registerButton) {
        _registerButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_registerButton setTitle:@"注册" forState:UIControlStateNormal];
        _registerButton.titleLabel.font = [UIFont systemFontOfSize:15.0f];
        _registerButton.titleLabel.textColor = [UIColor whiteColor];
        [_registerButton addTarget:self action:@selector(pushLoginViewController) forControlEvents:UIControlEventTouchUpInside];
    }
    return _registerButton;
}

-(void)pushLoginViewController{
    if (_landingBlock) {
        _landingBlock();
    }
}

@end
